<extend name="Public/layout"/>
<block name="head">
<link rel="stylesheet" href="__PUBLIC__css/opinion-comment.css">
<style type="text/css">
.footer{
  display: none;
}
</style>
</block>

  <block name="main">
    <div class="container">
      <div class="short-one">
          <div class="one-title">
            <h4>请选择您对平台的评价</h4>
          </div>
          <a class="one-have">
            <p>您已选择 
              <switch name="colligate" >
                <case value="1" break="1">放心投</case>
                <case value="2">可以投 </case>
                <case value="3">谨慎投 </case>
                <case value="4">不要投 </case
                  ></switch>，点击更改 > 
            </p>
          </a>
        </div>
        <div class="opinion-detail">
          <ul>
            <li>
              <h4 class="opinion-href">舆情链接</h4>
              <input type="text" name="url" <if condition='$edit eq 1'> value="{$circle_info.url}"</if> <notempty name="Think.get.url">value="{:base64_decode($_GET['url'])}"</notempty> placeholder="输入网址 如：http://www.8hjie.com"/>
              
            </li>
            <li>
              <h4 class="opinion-form">舆情来源</h4>
              <input type="text" name="source" <if condition='$edit eq 1'> value="{$circle_info.source}"</if><notempty name="Think.get.source">value="{:base64_decode(str_replace(" ","+",$_GET['source']))}"</notempty> placeholder="输入来源名字"/>
            </li>
            <li>
              <h4 class="opinion-title">舆情标题</h4>
              <input type="text" name="title" <if condition='$edit eq 1'> value="{$circle_info.title}"</if> <notempty name="Think.get.title">value="{:base64_decode(str_replace(" ","+",$_GET['title']))}"</notempty> placeholder="输入舆情标题"/>
            </li>
          </ul>
        </div>
        <div class="short-comment" id="wordCounta">
            <textarea class="comment-textarea" name="content" cols="5" type="text" maxlength="500" placeholder="您已实名认证，请根据您的情况作出实际评价，不造谣，不夸大。一旦发现评论出现恶意造谣等虚假信息，将对评论本人进行曝光，封号处理，如有违法，将提交公安机关处理。" ><if condition='$edit eq 1'> {$circle_info.content}</if></textarea>
            <span class="wordWrap">
            <var class="word">200</var>/ 200
            </span>
        </div>
        <div class="submit" onclick="sub()">
        <p>提交</p>
      </div> 
    </div>
    <!-- 弹出层 -->
   <div class="popup" <notempty name="colligate">style="display:none"</notempty>>
        <div class="popup-com">
          <div class="popup-title">
            <p>请选择您对平台的评价</p>
          </div>
          <div class="popup-con">
            <ul class="clearfix" id="tag">
              <li>
                <div class="unchecked one <if condition='$colligate eq 1'> active</if>" attr_id='1'>
                  <p>放心投</p>
                </div>
              </li>
              <li>
                <div class="unchecked two <if condition='$colligate eq 2'> active</if>"  attr_id='2'>
                  <p>可以投</p>
                </div>
              </li>
              <li>
                <div class="unchecked three <if condition='$colligate eq 3'> active</if>"  attr_id='3'>
                  <p>谨慎投</p>
                </div>
              </li>
              <li>
                <div class="unchecked four <if condition='$colligate eq 4'> active</if>"   attr_id='4'>
                  <p>不要投</p>
                </div>
              </li>
            </ul>
             <ul class="clearfix have">
              <li>
                <div class="unchecked <if condition='$is_invest eq 1'> haveactive</if>" attr_id='1'>
                  <p>已投资</p>
                </div>
              </li>
              <li>
                <div class="unchecked <if condition='$is_invest eq 0'> haveactive</if>"   attr_id='0'>
                  <p>未投资</p>
                </div>
              </li>
            </ul>
          </div>
<!--           <div class="popup-check">
            <div class="p-check <if condition='$is_invest eq 1'> p-active</if>" <if condition='$is_invest eq 1'>attr_check="1"<else/>attr_check="0"</if>></div>
            <p>未投资</p>
          </div> -->
          <div class="popup-submit">
            <p>下一步</p>
          </div>
        </div>
    </div>
  </block>
  <block name="js">
    <script type="text/javascript">
        document.addEventListener("touchmove",function(e){
          e.preventDefault();
          e.stopPropagation();
      },false); 
        function sub(){
          var l_len = $('.active').length;
            if(l_len==0){
                layer.open({
                  content: '您还未选择标签！'
                  ,skin: 'msg'
                  ,time: 2 //2秒后自动关闭
                });
                return;
            }
          var platform_id ="{$_GET['id']}";
          var title = $('input[name="title"]').val();
          var url = $('input[name="url"]').val();
          var source = $('input[name="source"]').val();
          var content = $('textarea[name="content"]').val();
          var edit="{$edit}";
          if(!title){
                layer.open({
                  content: '您还未输入舆情标题！'
                  ,skin: 'msg'
                  ,time: 2 //2秒后自动关闭
                });
                return;
            }
            if(!url){
                layer.open({
                  content: '您还未输入舆情链接！'
                  ,skin: 'msg'
                  ,time: 2 //2秒后自动关闭
                });
                return;
            }else{
              var Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
              var objExp=new RegExp(Expression);
              if (objExp.test(url) != true) {
                layer.open({
                  content: '请输入正确的舆情链接！'
                  ,skin: 'msg'
                  ,time: 2 //2秒后自动关闭
                });
                return;
              };
            }
            if(!source){
                layer.open({
                  content: '您还未输入舆情来源！'
                  ,skin: 'msg'
                  ,time: 2 //2秒后自动关闭
                });
                return;
            }
            if(!content){
                layer.open({
                  content: '您还未输入舆情评价！'
                  ,skin: 'msg'
                  ,time: 2 //2秒后自动关闭
                });
                return;
            }
          if(edit){
            var info_id = "{$_GET[info_id]}"
            var postdata = {platform_id:platform_id,title:title,url:url,source:source,content:content,edit:1,info_id:info_id};
          }else{
            var postdata = {platform_id:platform_id,title:title,url:url,source:source,content:content};
          }
          
          $.post("{:U('Circle/circle_opinion')}",postdata,function(res) {
            if(edit){
              layer.open({
                content:res.msg
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
                ,end:function(){history.go(-1)}
              });
            }else{
              layer.open({
                content:res.msg
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
                ,end:function(){location.href="/Home/circle/circle_info/id/"+platform_id}
              });
            }
          })


        }

       $('.one-have').click(function() {
          $('.popup').css('display','block');
        });
       $('.have > li > div').each(function(index, v) {
            $(v).click(function(){
              $('.have > li > div').each(function(index, v){
                $(v).removeClass('haveactive')
              });
              $(v).addClass('haveactive');
            });
          });
        $('.popup-submit').click(function() {
          
          var  text ='',temp = 0;
          $('#tag > li > div').each(function(index, v) {
            if($(v).hasClass('active')){
              temp +=1;
            }
            $('.one-have > p')[0].innerHTML = '您已选择'+text+'，点击更改 >';
          });
          
          if(temp>1){
            layer.open({
              content: '最多只能选择一个评价！'
              ,skin: 'msg'
              ,time: 2 //2秒后自动关闭
            });
          }else if(temp==0){
            console.log(1)
             layer.open({
              content: '必须要选择一个评价！'
              ,skin: 'msg'
              ,time: 2 //2秒后自动关闭
            });
          }else{console.log(2)
            //提交综合评价
            var colligate = $('#tag > li > .active').attr('attr_id');
            var is_invest = $('.have > li > .haveactive').attr('attr_id');
            var platform_id = '{$_GET["id"]}';
            $.post('/Home/circle/grade',{
               platform_id:platform_id,
                colligate:colligate,
                is_invest:is_invest
            },function(res){
                  if(res.err!=0){
                         layer.open({
                            content:"您未改变评价！"
                            ,skin: 'msg'
                            ,time: 2 //2秒后自动关闭
                          });
                        
                  }
                      $('.popup').css('display','none');
                      document.addEventListener("touchmove",function(e){
                           e.returnValue = true;
                      },false);
                      $('#tag > li > div').each(function(index, v) {
                          if($(v).hasClass('active')){
                              text += $(v).children('0').prevObject["0"].innerText;
                          }
                          $('.one-have > p')[0].innerHTML = '您已选择'+text+'，点击更改 >';
                      });
            })
           
        }
        });




    $(function(){
        var wordCount = $("#wordCounta"),
            textArea = wordCount.find("textarea"),
            word = wordCount.find(".word");
        statInputNum(textArea,word);
    });
    function statInputNum(textArea,numItem) {
        var max = numItem.text(),
            curLength;
        textArea[0].setAttribute("maxlength", max);
        curLength = textArea.val().length;
        numItem.text(max - curLength);
        textArea.on('input propertychange', function () {
            var _value = $(this).val().replace(/\n/gi,"");
            numItem.text(max - _value.length);
        });
    }
            // 点击评价
          $('#tag > li > div').each(function(index, v) {
            $(v).click(function(){
              $('#tag > li > div').each(function(index, v){
                $(v).removeClass('active')
              });
              $(v).addClass('active');
            });
          });
          // 是否已投资
        $('.p-check').click(function() {
          if ($('.p-check').hasClass('p-active')) {
            $('.p-check').removeClass('p-active');
            $('.p-check').attr('attr_check','0');
            $('.p-check~p').html('未投资');
          }else{
            $('.p-check').addClass('p-active');
            $('.p-check').attr('attr_check','1');
            $('.p-check~p').html('已投资');
          };
        });
    </script>
  </block>